package com.millstein.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.millstein.commonutils.Result;
import com.millstein.eduservice.entity.EduCourse;
import com.millstein.eduservice.entity.EduTeacher;
import com.millstein.eduservice.service.EduCourseService;
import com.millstein.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    /**
     * 查询前8个热门课程，查询前4个名师
     * @return
     */
    @GetMapping("index")
    public Result index() {
        QueryWrapper<EduCourse> cWrapper = new QueryWrapper<>();
        cWrapper.orderByDesc("id").last("limit 8");
        List<EduCourse> courses = eduCourseService.list(cWrapper);
        
        QueryWrapper<EduTeacher> tWrapper = new QueryWrapper<>();
        tWrapper.orderByDesc("id").last("limit 4");
        List<EduTeacher> teachers = eduTeacherService.list(tWrapper);

        return Result.ok().data("courses", courses).data("teachers", teachers);
    }
}
